<template>
  <div>
    <!-- 面包屑导航区 -->
    <el-breadcrumb separator-class="el-icon-arrow-right">
      <el-breadcrumb-item :to="{ path: '/home' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>固定车主管理</el-breadcrumb-item>
      <el-breadcrumb-item>停车信息管理</el-breadcrumb-item>
    </el-breadcrumb>

    <el-card class="box-card">
      <!-- 列表区域 -->
      <el-table :data="fixedList" border stripe>
        <el-table-column type="index" label="编号"></el-table-column>
        <el-table-column prop="fixedId" label="记录编号"> </el-table-column>
        <el-table-column prop="cardId" label="IC卡号"> </el-table-column>
        <el-table-column prop="userName" label="车主名称"> </el-table-column>
        <el-table-column prop="cardNum" label="车牌号码"> </el-table-column>
        <el-table-column
          prop="entryTime"
          :formatter="dateFormat"
          label="入场日期"
        >
        </el-table-column>
        <el-table-column label="是否出场">
          <template slot-scope="scope">
            {{ scope.row.status == 0 ? '未出场' : '已出场' }}
          </template>
        </el-table-column>
        <el-table-column label="操作" fixed="right">
          <template slot-scope="scope">
            <el-tooltip
              class="item"
              effect="dark"
              content="删除记录"
              placement="top"
              :enterable="false"
            >
              <el-button
                type="danger"
                icon="el-icon-delete"
                circle
                @click="fixedOutById(scope.row.fixedId)"
                :disabled="scope.row.status == 0 ? true : false"
              ></el-button>
            </el-tooltip>
          </template>
        </el-table-column>
      </el-table>

      <!-- 分页区域 -->
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="pageNum"
        :page-sizes="[1, 3, 5, 10]"
        :page-size="pageSize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total"
      >
      </el-pagination>
    </el-card>
  </div>
</template>

<script>
import moment from 'moment'
export default {
  data() {
    return {
      fixedList: [],
      total: null,
      //   当前的页数
      pageNum: 1,
      //   当前每页显示多少条数据
      pageSize: 10,
    }
  },
  mounted() {
    this.getFixedList()
  },
  methods: {
    async getFixedList() {
      const { data: res } = await this.$http.post('fix/list', {
        pageNum: this.pageNum,
        pageSize: this.pageSize,
      })
      this.total = res.total
      this.fixedList = res.list
    },
    handleSizeChange(newSize) {
      this.pageSize = newSize
      this.getFixedList()
    },
    handleCurrentChange(newPageNum) {
      this.pageNum = newPageNum
      this.getFixedList()
    },
    dateFormat(date) {
      return moment(date.entryTime).format('YYYY-MM-DD HH:mm:ss')
    },
    // 删除记录
    async fixedOutById(fixedId) {
      const confirmResult = await this.$confirm('确定删除?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning',
      }).catch((err) => err)
      // 如果用户确认删除，则返回值为字符串 confirm
      // 如果用户取消删除，则返回值为字符串 cancel
      if (confirmResult !== 'confirm') {
        return this.$message.info('已取消删除')
      }
      const res = await this.$http.get('fix/delete/' + fixedId)
      this.$message.success('删除成功')
      this.getFixedList()
    },
  },
}
</script>

<style lang="less" scoped></style>
